package com.gsq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gsq.common.pojo.Sys_menu;
import com.gsq.mapper.MenuMapper;
import com.gsq.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;
    @Override
    public List<Sys_menu> getMenu() {
        // 查询一级菜单
        QueryWrapper<Sys_menu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0);
        List<Sys_menu> oneList = menuMapper.selectList(queryWrapper);
        // 查询二级菜单
        for (Sys_menu twoList : oneList){
            queryWrapper.clear();
            queryWrapper.eq("parent_id", twoList.getId());
            List<Sys_menu> children = menuMapper.selectList(queryWrapper);
            twoList.setChildren(children);
        }
        return oneList;
    }
}
